package cn.cdut.yiwenqian.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.orm.hibernate4.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import cn.cdut.yiwenqian.dao.interfaces.IUserDao;
import cn.cdut.yiwenqian.entity.CdutPostUsers;
@Scope("singleton")
@Repository
public class UserDaoImpl extends HibernateDaoSupport implements IUserDao {

	@Override
	public CdutPostUsers findUserByAccountPassWord(String account, String password) {
		CdutPostUsers u=new CdutPostUsers();
		u.setAccount(account);
		u.setPassword(password);
		List<CdutPostUsers> list=this.getHibernateTemplate().findByExample(u);
		if(list.size()>0){
			return  list.get(0);
		}else{
			return null;
		}
		
	}

	@Override
	public CdutPostUsers findUserById(Integer unumber) {
		return this.getHibernateTemplate().get(CdutPostUsers.class, unumber);
	}

	@Override
	public List<CdutPostUsers> findAllTeacher() {
		// TODO Auto-generated method stub
		return this.getHibernateTemplate().loadAll(CdutPostUsers.class);
	}

	@Override
	public void saveNweUser(CdutPostUsers user) {
		this.getHibernateTemplate().save(user);
		
	}

	@Override
	public void updateUser(CdutPostUsers user) {
		this.getHibernateTemplate().update(user);
		
	}

	@Override
	public List<CdutPostUsers> findUserByWorkNumber(String unumber) {
		CdutPostUsers u=new CdutPostUsers();
		u.setWorkNumber(unumber);
		return (List<CdutPostUsers>) this.getHibernateTemplate().findByExample(u);
	}

	@Override
	public List<CdutPostUsers> fingUserListByAccount(String account) {
		CdutPostUsers u=new CdutPostUsers();
		u.setAccount(account);
		return (List<CdutPostUsers>) this.getHibernateTemplate().findByExample(u);
	}
	@Resource
	public void setMySessionFactory(SessionFactory sessionFactory){
		super.setSessionFactory(sessionFactory);
	}

}
